/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;
import Entidad.Usuario;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author Jhon
 */
public class DAOUsuario {
    
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Arq_Taller1auxPU");
        
    
    public boolean create(Usuario entity,StringBuffer error) {
        boolean       ret = false;
        EntityManager em  = emf.createEntityManager();
        
        try {
            em.getTransaction().begin();
            em.persist(entity);
            //em.merge(entity);
            em.getTransaction().commit();
            ret = true;
        } catch (Exception e) {
            error.append(e.getMessage());
            ret = false;
//          e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            //if(em!=null && em.getTransaction().isActive()){
            //em.clear();    
            //em.close();}
            return ret;
        }
    }
}
